#!/bin/bash

if [ $# -eq 0 ];
then
	echo -e "\e[31m请输入要kill的服务器! 如:./onesecondkill.sh svrd\e[0m"
	exit
fi

SET_ID=$1

FOLDER="/home/yt$SET_ID/code/run"
if [ ! -e $FOLDER ];then
    FOLDER="/data/yt${1}/code/run"
	if [ ! -e ${FOLDER} ];then
		FOLDER="/home/${1}/code/run"
		if [ ! -e ${FOLDER} ];then
			FOLDER="/data/${1}/code/run"
			if [ ! -e ${FOLDER} ];then
				echo -e "\e[31m${1}目录不存在!\e[0m"
				exit 1
			fi
		fi
	fi
fi

date=$(date '+%Y-%m-%d %H:%M:%S')

find $FOLDER/*/ -name "*.pid"|grep -v 234|while read line
do
	PID=`cat $line`
	# echo "$date $line $PID" >> onesecondkill.log
	kill -9 $PID
	rm -rf $line
done

#if [ $1 -eq 1 ] || [ $1 -eq 10 ];then
#	ps -fe |awk '{print $2 " " $8}'|grep svrd |grep -v 101|grep $1|awk '{print $1}'|xargs kill -9
#else
#	ps -fe |awk '{print $2 " " $8}'|grep svrd |grep $1|awk '{print $1}'|xargs kill -9
#fi

#SRC_FILE="/"
#cd ${SRC_FILE}
#ps -ef | grep -v grep | grep $1 |grep svrd | awk '{print $2}' | xargs kill -9 

#if [ $? -ne 0 ]
#then
#	echo -e "\e[31m指令有误!\e[0m"
#fi

#sleep 2
#ps -ef | grep -v grep | grep $1| grep svrd


